<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>安伴后台管理系统-设备海报列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <script type="text/javascript" src="/static/js/jquery.cookie.js"></script>
    <script type="text/javascript" src="/static/js/base64.decode.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="{{urlfor "admin.DevicePictureController.ShowAllList"}}"
       title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
                    <button class="layui-btn" onclick="xadmin.open('添加设备海报','{{urlfor "admin.DevicePictureController.Add" ":id" .deviceId}}')">
                        <i class="layui-icon"></i>添加
                    </button>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>
                                <input type="checkbox" lay-filter="checkall" name="" lay-skin="primary">
                            </th>
                            <th>ID</th>
                            <th>海报标题</th>
                            <th>海报图片</th>
                            <th>操作</th>
                        </thead>
                        <tbody class="x-cate">
                        {{range .recordList}}
                            <tr>
                                <td>
                                    <input type="checkbox" class="id-check" value="{{.Id}}" lay-skin="primary">
                                </td>
                                <td>{{.Id}}</td>
                                <td>{{.Title}}</td>
                                <td>
                                    <a target="_blank" href="{{.Url}}">
                                        <img src="{{.Url}}">
                                    </a>
                                </td>
                                <td class="td-manage">
                                    <a title="编辑" onclick="xadmin.open('编辑','{{urlfor "admin.DevicePictureController.Edit" ":id" .Id}}')" href="javascript:;">
                                        <i class="layui-icon">&#xe642;</i>
                                    </a>
                                </td>
                            </tr>
                        {{else}}
                            <tr>
                                <td colspan="100" style="text-align: center;font-weight: bold;color: #ff6666;">没有数据</td>
                            </tr>
                        {{end}}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>

    var canSubmit = true,
        xsrf = '';

    layui.use(["form"], function () {

        $ = layui.jquery;
        var form = layui.form;

        $(function () {
            xsrf = base64_decode(Cookies.get("_xsrf").split("|")[0]);
        });

        // 监听全选
        form.on('checkbox(checkall)', function(data){
            if(data.elem.checked){
                $('tbody input').prop('checked',true);
            }else{
                $('tbody input').prop('checked',false);
            }
            form.render('checkbox');
        });

    });

    function delAll() {

        layer.confirm('确定要删除吗?', function(index){

            var ids = [];
            // 获取选中的id
            $('.x-cate .id-check').each(function(index, el) {
                if($(this).prop('checked')){
                    ids.push($(this).val())
                }
            });
            if (ids.length <= 0) {
                layer.msg("请选择要删除的海报", {icon: 2});
                return false;
            }
            ids = ids.join(',');

            if (!canSubmit) return false;
            var loadIndex = layer.load();
            canSubmit = false;

            $.ajax({
                url: '{{urlfor "admin.DevicePictureController.Del"}}',
                type: 'POST',
                data: {_xsrf: xsrf, ids: ids},
                dataType: 'json',
                success: function (res) {

                    layer.close(loadIndex);
                    canSubmit = true;

                    if (res.status != 1) {
                        layer.msg(res.msg, {icon: 2});
                        return false;
                    }

                    layer.alert(res.msg, {icon: 6}, function () {
                        location.reload();
                    });

                }
            });

            layer.close(index);
        });
    }

</script>
</html>